﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>工艺产能管理</title>
    <link href="~/Scripts/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <link href="~/Content/formstyles.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "OperMgr", "KeyName": "OperMgr" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            var oldSelectOperGroupId;   //上次点选的opergroupid
                            $("#ui_oper_dg").datagrid({       //初始化datagrid
                                url: "/Produce/GetAllOperGroupInfo?r=" + Math.random(),
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                idField: 'OperGroupID',
                                sortName: 'OperGroupID',
                                sortOrder: 'asc',
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[
                                                 { field: 'OperGroupID', title: '工艺组编码', width: 80 }
                                ]],
                                columns: [[
                                           { field: 'OperGroupName', title: '工艺组名称', width: 120 },
                                           { field: 'DayTime', title: '日产能', width: 80 },
                                           { field: 'WeekTime', title: '周产能', sortable: false, hidden: true, width: 80 },
                                           { field: 'MonthTime', title: '月产能', sortable: false, hidden: true, width: 80 },
                                            { field: 'AlertValue', title: '预警阈值(%)', width: 80 },
                                             {
                                                 field: 'IsCheck', title: '启用', width: 80,
                                                 formatter: function (value, row, index) {
                                                     return value == true ? '<img src="../../Content/themes/icon/chk_checked.gif" alt="已启用" title="项目已启用" />' : '<img src="../../Content/themes/icon/chk_unchecked.gif" alt="未启用" title="项目未启用"  />';
                                                 }

                                             },
                                           { field: 'UpdateTime', title: '更新时间', hidden: true, width: 150 },
                                           { field: 'UpdateBy', title: '更新人', hidden: true, width: 60 },
                                           {
                                               field: 'Remark', title: '描述', width: 250,
                                               formatter: function (value, row, index) {
                                                   return value.length > 20 ? '<span title="' + value + '">' + value + '</span>' : value;
                                               }
                                           }
                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar,
                                onSelect: function (rowIndex, rowData) {
                                    if (oldSelectOperGroupId == rowData.OperGroupID) {
                                        return;
                                    }
                                    oldSelectOperGroupId = rowData.OperGroupID;
                            var $ui_oper_layout = $("#ui_oper_layout");
                            var eastOperMember = $ui_oper_layout.layout("panel", "east");
                            if (eastOperMember.panel("options").collapsed) {   //判断是否展开
                                $ui_oper_layout.layout("expand", "east");
                            }
                            eastOperMember.panel("setTitle", rowData.OperGroupName + "成员");
                            if ($("#ui_oper_member_dg").data("datagrid")) {
                                $("#ui_oper_member_dg").datagrid({       //请求数据
                                    url: "/Produce/GetOperByGroupID?OperGroupID=" + rowData.OperGroupID+"&r=" + Math.random(),
                                });
                            }
                            else {
                                $("#ui_oper_member_dg").datagrid({       //初始化datagrid
                                    url: "/Produce/GetOperByGroupID?OperGroupID=" + rowData.OperGroupID + "&r=" + Math.random(),
                                    striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
                                    idField: 'ID',
                                    sortName: 'OperID',
                                    sortOrder: 'asc',
                                    pageList: [20, 40, 60, 80, 100],
                                    columns: [[
                                          { field: 'OperID', title: '工艺编码', sortable: true, width: 80 },
                                          { field: 'OperName', title: '工艺名称', sortable: true, width: 120 },
                                          { field: 'Remark', title: '说明', sortable: false, width: 150 }]]
                                });
                            }
                        }
                            
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })
        })

        
    
        //新增
        function AddOperMgr() {
            $("<div/>").dialog({
                id: "ui_Oper_add_dialog",
                href: "/Produce/OperGroupAdd?r=" + Math.random(),
                title: "添加工艺组",
                height: 300,
                width: 400,
                modal: true,
                buttons: [{
                    id: "ui_oper_add_btn",
                    text: '添 加',
                    handler: function () {
                        $.ajax({
                            url: "/Produce/AddOperGroup?r=" + Math.random(),
                            data: {
                         "FoperID": $("#OpergroupID").val(),
                        "OperNote": $("#Opergroupname").val(),
                        // Icon = $("#comboxIconTree").combotree("getValues").toString();//$("#txtIcon").val();
                        "DayTime": $('#DayTime').val(),
                        "Remark": $("#Remark").val(),
                        "AlertValue": $("#AlertValue").val(),
                        "IsCheck": $("#IsCheckOper").switchbutton("options").checked

                            },
                            dataType: "json",
                            type: "POST",                          
                            success: function (data) {
                                if (data.success) {
                                    $("#ui_Oper_add_dialog").dialog('destroy');
                                    $.show_alert("提示", "添加成功！");
                                    $("#ui_oper_dg").datagrid("reload");
                                } else {                                   
                                    $.show_alert("提示", data.msg);
                                }
                            }
                        }); 
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_Oper_add_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    $("#OpergroupID").focus();
                },
                onClose: function () {
                    $("#ui_Oper_add_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //修改
        function EditOperMgr() {
            var row = $("#ui_oper_dg").datagrid("getChecked");
            if (row.length < 1) {
                $.show_alert("提示", "请先选择要修改的工艺");
                return;
            }
            $("<div/>").dialog({
                id: "ui_oper_edit_dialog",
                href: "/Produce/OperGroupAdd?r=" + Math.random(),
                title: "修改工艺组参数",
                height: 300,
                width: 400,
                modal: true,
                toolbar: [{
                    text: '保存',
                    iconCls: 'icon-save',
                    handler: function () {
                        $.ajax({     //提交数据保存
                            url: "/Produce/OperGroupEdit?r=" + Math.random(),
                            data: {
                                "FoperID": $("#OpergroupID").val(),
                                "OperNote": $("#Opergroupname").val(),
                                "DayTime": $('#DayTime').val(),
                                "Remark": $("#Remark").val(),
                                "AlertValue": $("#AlertValue").val(), 
                                "IsCheck": $("#IsCheckOper").switchbutton("options").checked
                            },
                            type: "post",
                            dataType: "json",
                            timeout: 5000,
                            success: function (data) {
                                if (data.success) {
                                    $("#ui_oper_edit_dialog").dialog('destroy');
                                    $.show_alert("提示", data.msg);
                                    $("#ui_oper_dg").datagrid("reload");
                                } else {
                                    $.show_alert("提示", data.msg);
                                }
                            },
                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                if (textStatus == "timeout") {
                                    $.show_alert("提示", "请求超时，请刷新当前页重试！");
                                }
                                else {
                                    $.show_alert("错误", textStatus + "：" + errorThrown);
                                }
                            }
                        })
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cross',
                    handler: function () { $("#ui_oper_edit_dialog").dialog('destroy'); }
                }],
                onLoad: function () {
                    $("#OpergroupID").textbox('setValue', row[0].OperGroupID);
                    $("#OpergroupID").textbox('disable');
                    $("#Opergroupname").textbox('setValue', row[0].OperGroupName);
                    $("#DayTime").textbox('setValue', row[0].DayTime);
                    $("#Remark").textbox('setValue', row[0].Remark);
                    $("#AlertValue").textbox('setValue', row[0].AlertValue);
                    if (row[0].IsCheck) {
                        $("#IsCheckOper").switchbutton("check");
                    }
                   
                },
                onClose: function () {
                    $("#ui_oper_edit_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //删除
        function DelOperMgr() {
            var rows = $("#ui_oper_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要删除的分录");
                return;
            }
            $.messager.confirm('提示', '确定删除选中行吗？', function (r) {
                if (r) { 
                     $.ajax({
                         url: "/Produce/DelOperGroup?r=" + Math.random(),
                        data: {
                            "FoperID": rows[0].OperGroupID
                        },
                        type: "POST",
                       // dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", "删除成功！");
                                $("#ui_oper_dg").datagrid("reload");
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }

        //分配成员
        function setmember() {
            var row = $("#ui_oper_dg").datagrid("getChecked");
            if (row.length < 1) {
                $.show_alert("提示", "请先勾选要分配按钮的菜单");
                return;
            }
            //if (row[0].ParentId == 0 || row[0].ParentId == "") {
            //    $.show_alert("提示", "根节点无法分配按钮");
            //    $("#ui_menu_dg").datagrid('clearSelections').datagrid('clearChecked');
            //    return;
            //}

            $("<div/>").dialog({
                id: "setdialog",
                href: "/Produce/OpermemberSet?r=",// + Math.random(),
                title: "分配工艺",
                height: 200,
                width: 400,
                modal: true,
                buttons: [{
                    id: "btnmenubuttonsave",
                    text: '保 存',
                    handler: function () {
                        $("#SetMenuButtonForm").form("submit", {
                            url: "/Produce/SetOperMember?r="  + Math.random(),
                            onSubmit: function (param) {
                                $('#btnmenubuttonsave').linkbutton('disable');
                                param.opergroupid = $("#hidid").val();
                                param.operids = $("#comOperTree").combotree("getValues").toString();
                                if ($(this).form('validate')) {
                                    return true;
                                }
                                else {
                                    $('#btnmenubuttonsave').linkbutton('enable');   //恢复按钮
                                    return false;
                                }
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');    //转成json格式
                                if (dataJson.success) {
                                    $("#setdialog").dialog('destroy');  //销毁dialog对象
                                    $("#ui_oper_member_dg").datagrid('reload');//刷新工艺成员
                                    $.show_alert("提示", dataJson.msg);

                                } else {
                                    $('#btnmenubuttonsave').linkbutton('enable');    //恢复按钮
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }],
                onLoad: function () {
                    $("#hidid").val(row[0].OperGroupID);
                    $("#txtMenuBtnName").val(row[0].OperGroupName);
                    //获取此菜单配置的按钮 设置按钮 ui_menubutton_button 选中
                    $.ajax({
                        url: "/Produce/GetOperByGroupID?&r=" + Math.random(),
                        data: {
                            'OperGroupID': row[0].OperGroupID,
                            'view': 'combotree'
                        },
                        success: function (data) {
                            if (data != null && data != "") {
                                $('#comOperTree').combotree('setValues', data.split(','));
                            }
                        }
                    });
                },
                onClose: function () {
                    $("#setdialog").dialog('destroy');  //销毁dialog对象
                  
                }
            });

        }

    </script>
</head>
<body>
    <div id="ui_oper_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'east',split:true,border:true,collapsed:true" title="工艺组成员"
             style="width: 480px;">
            <table id="ui_oper_member_dg" data-options="fit:true,border:false"></table>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_oper_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>
</body>
</html>
